from common.b_yamlOperate import pathConf,openReade



def getStrLine(str,dfStr):
    """
    获取指定字符串所在的行
    :param: str 原字符串
    :param: dfStr 指定字符串
    :return: 返回包含指定字符串的行
    """
    data = str.split("\n")
    for i in range(len(data)):
        if dfStr in data[i]:
            da = data[i].lstrip().rstrip()
            return da

def getStrLines(str,dfStr):
    """
    获取指定字符串所在的所有行
    :param: str 原字符串
    :param: dfStr 指定字符串
    :return: 返回包含指定字符串的所有行
    """
    strResuli = ""
    liststr = []
    data = str.split("\n")
    for i in range(len(data)):
        if dfStr in data[i]:
            da =data[i].lstrip().rstrip()
            if da not in liststr:
                liststr.append(da)
                strResuli = strResuli + da + "\n"
    return strResuli

if __name__ == "__main__":
    pass
    # dta = openReade(pathConf.get_reportLog())
    # line = getStrLines(dta,":uri")
    # print(line)
    log = openReade(pathConf.get_reportLog())
    print("打印log：")
    print(log)
    logline = getStrLines(log,":uri")
    print("logline：")
    print(logline)
    if len(logline) > 4:
        print("接口异常")
        # Rob.send_message(message="以下接口存在异常，请关注：" + "\n" + logline)
    else:
        print("正常")